// pages/announce/announce.js
const regex = require('../../utils/regex')
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    gangwei: "",
    xinzi: "",
    phone: "",
    content: "",
    name: "",
    sex: "",
    age: "",
    salary: "",
    post: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  changegangwei(e){
    this.setData({
      gangwei: e.detail
    })
  },
  changexinzi(e) {
    this.setData({
      xinzi: e.detail
    })
  },
  changephone(e) {
    this.setData({
      phone: e.detail
    })
  },
  changecontent(e) {
    this.setData({
      content: e.detail
    })
  },
  changename(e) {
    this.setData({
      name: e.detail
    })
  },
  changesex(e) {
    this.setData({
      sex: e.detail
    })
  },
  changeage(e) {
    this.setData({
      age: e.detail
    })
    console.log(e.detail)
  },
  changesalary(e) {
    this.setData({
      salary: e.detail
    })
  },
  changepost(e) {
    this.setData({
      post: e.detail
    })
  },
  submit(e) {
    var that = this;
    if (this.data.name == "") {
      wx.showToast({
        icon: 'none',
        title: '请输入姓名'
      })
      return
    }
    if (this.data.sex == "") {
      wx.showToast({
        icon: 'none',
        title: '请输入性别'
      })
      return
    }
    if (this.data.age == "") {
      wx.showToast({
        icon: 'none',
        title: '请输入年龄'
      })
      return
    }
    if (this.data.salary == "") {
      wx.showToast({
        icon: 'none',
        title: '请输入期望薪资'
      })
      return
    }
    if (this.data.post == "") {
      wx.showToast({
        icon: 'none',
        title: '请输期望岗位'
      })
      return
    }

    wx.request({
      url: app.d.severUrl + 'jobwant_add',
      method: 'GET',
      data: {
        token: wx.getStorageSync("token"),
        name: that.data.name,
        sex: that.data.sex,
        old: that.data.age,
        hope_job: that.data.post,
        hope_money: that.data.salary
      },
      success: res => {
        if (res.data.code == 0) {
          wx.showToast({
            icon: 'none',
            title: res.data.msg
          })
          wx.navigateTo({
            url: '/pages/index/talentMarket/talentMarket/talentMarket?active=1',
          })
        } else {
          wx.showToast({
            icon: 'none',
            title: res.data.msg
          })
        }
      }
    })

  },
  submitZp(e) {
    var that = this;

    if (that.data.gangwei == "") {
      wx.showToast({
        icon: 'none',
        title: '请输入招聘岗位'
      })
      return
    }
    if (that.data.xinzi == "") {
      wx.showToast({
        icon: 'none',
        title: '请输入招聘薪资'
      })
      return
    }
    if (that.data.phone == "") {
      wx.showToast({
        icon: 'none',
        title: '请输入联系方式'
      })
      return
    }

    if (!regex.phone.test(that.data.phone)) {
      wx.showToast({
        icon: 'none',
        title: '手机号格式错误'
      })
      return
    }
    if (that.data.content == "") {
      wx.showToast({
        icon: 'none',
        title: '请输入招聘简介'
      })
      return
    }

    wx.request({
      url: app.d.severUrl + 'recruit_add',
      method: 'POST',
      data: {
        token: wx.getStorageSync("token"),
        post: that.data.gangwei,
        salary: that.data.xinzi,
        phone: that.data.phone,
        brief_introduction: that.data.content
      },
      success: res => {
        if (res.data.code == 0) {
          wx.showToast({
            icon: 'none',
            title: res.data.msg
          })
          wx.navigateTo({
            url: '/pages/index/talentMarket/talentMarket/talentMarket',
          })
        } else {
          wx.showToast({
            icon: 'none',
            title: res.data.msg
          })
        }
      },
      fail: error => {
        wx.showToast({
          icon: 'none',
          title: error.data.msg
        })
      }
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})